package com.scholarship.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.scholarship.system.entity.Teacher;
import com.scholarship.system.mapper.TeacherMapper;
import com.scholarship.system.service.TeacherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 导师服务实现类
 */
@Service
public class TeacherServiceImpl implements TeacherService {

    private static final Logger log = LoggerFactory.getLogger(TeacherServiceImpl.class);

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public void addTeacher(Teacher teacher) {
        log.info("添加导师信息: {}", teacher);
        teacherMapper.insert(teacher);
    }

    @Override
    public void updateTeacher(Teacher teacher) {
        log.info("更新导师信息: id={}", teacher.getId());
        teacherMapper.updateById(teacher);
    }

    @Override
    public void deleteTeacher(Long id) {
        log.info("删除导师: id={}", id);
        teacherMapper.deleteById(id);
    }

    @Override
    public Teacher getTeacherById(Long id) {
        log.info("获取导师信息: id={}", id);
        return teacherMapper.selectById(id);
    }

    @Override
    public List<Teacher> getTeacherList() {
        log.info("获取导师列表");
        return teacherMapper.selectList(null);
    }

    @Override
    public Teacher getTeacherByUserId(Long userId) {
        log.info("根据用户ID获取导师信息: userId={}", userId);
        LambdaQueryWrapper<Teacher> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Teacher::getUserId, userId);
        return teacherMapper.selectOne(wrapper);
    }
}